
function initLayer(datalist){

    if(localStorage.getItem("newsData")){
        localStorage.removeItem("newsData");
    }

    LGlobal.box2d = new LBox2d();
    backLayer = new LSprite();
    addChild(backLayer);

    gameLayer = new LSprite();
    gameLayer.graphics.drawRect(0,"#a8ef68",[0,0,LGlobal.width,LGlobal.height],true,"#a8ef68");

    //背景图片显示
    bgbitmap = new LBitmap(new LBitmapData(datalist["bg"]));

    bgbitmap.x=0;
    bgbitmap.y=0;

    backLayer.addChild(gameLayer);
    gameLayer.addChild(bgbitmap);

    var fps = new FPS();
    fps.visible=false;
    backLayer.addChild(fps);

    boomSound = new LSound("./sound/bu.mp3");
    dropSound=new LSound("./sound/drop.mp3");
    zhiSound=new LSound("./sound/zhi.mp3");
    startSound=new LSound("./sound/select.mp3");

    addStage();
    addButton();

}

//增加按钮
function addButton(){
    /*遮罩层*/
    createMask(0.5);

    /*开始按钮*/
    buttonLayer=new LSprite();
    gameLayer.addChild(buttonLayer);

    //开始按钮初始
    var startButtonStyle = new LSprite();
    var buttonBitmap = new LBitmap(new LBitmapData(datalist["startBtn"]));
    buttonBitmap.x = (LStage.width - buttonBitmap.getWidth()) * 0.5;
    buttonBitmap.y = (LStage.height - buttonBitmap.getHeight()) * 0.5-60;
    startButtonStyle.addChild(buttonBitmap);

    //开始按钮点击下
    var startButtonOverStyle = new LSprite();
    var buttonBitmap = new LBitmap(new LBitmapData(datalist["startBtn"]));
    buttonBitmap.scaleX = 1.1;
    buttonBitmap.scaleY = 1.1;
    buttonBitmap.x = (LStage.width - buttonBitmap.getWidth()) * 0.5;
    buttonBitmap.y = (LStage.height - buttonBitmap.getHeight()) * 0.5-60;
    startButtonOverStyle.addChild(buttonBitmap);

    var startBtn = new LButton(startButtonStyle,startButtonOverStyle);
    buttonLayer.addChild(startBtn);
    startBtn.addEventListener(LMouseEvent.MOUSE_DOWN,function(){
        if(isStart == false){
            destoryMask();
            boomSound.setVolume(0);
            boomSound.play();
            boomSound.close();
            startSound.play();
            LTweenLite.to(buttonLayer,0.6,{
                alpha:0,
                onComplete:function(){
                    buttonLayer.visible = false;
                    buttonLayer.die();
                    buttonLayer.removeAllChild();
                    clearInterval(shakeListener);
                    setTimeout(function(){
                        gameStart();
                    },200)
                }
            });
        }
    });

    var pointer = new LSprite();
    var pointerBitmap = new LBitmap(new LBitmapData(datalist["pointer"]));
    pointerBitmap.x=shotLayer.x+44;
    pointerBitmap.y=shotLayer.y;
    pointer.addChild(pointerBitmap);
    buttonLayer.addChild(pointer);

    var shakeHand=function(){
        LTweenLite.to(pointer,1,{
            y:60,
            yspeed:4,
            delay:0.1,
            alpha:1,
            onUpdate:function(){

            },
            onComplete:function(){
                LTweenLite.to(pointer,1,{
                    y:0,
                    yspeed:4,
                    delay:0.1,
                    alpha:1,
                    onUpdate:function(){

                    },
                    onComplete:function(){

                    },
                    ease:Sine.easeIn
                });
            },
            ease:Sine.easeIn
        });
    };

    shakeHand();

    var shakeListener=setInterval(function(){
        shakeHand();
    },4000);
}

/*遮罩层开始*/
function createMask(alpha){
    maskLayer=new LSprite();
    maskLayer.graphics.drawRect(1,"#000",[0,0,LGlobal.width,LGlobal.height],true,"#000");
    maskLayer.alpha=alpha||0.6;
    gameLayer.addChild(maskLayer);
}

function destoryMask(){
    gameLayer.removeChild(maskLayer);
}

function hideLoading(mask){
    //清空loading
    mask.removeChild(arcLayer);
    mask.removeChild(loadingTextLayer);
    clearInterval(showLoadingGo);
}

function showLoading(mask){
    canShot=false;
    arcLayer = new LSprite();
    mask.addChild(arcLayer);
    loadingTextLayer = new LTextField();
    loadingTextLayer.color="#FFFFFF";
    loadingTextLayer.weight="bolder";
    loadingTextLayer.text="抽奖中";
    loadingTextLayer.size = 22;
    loadingTextLayer.x = LGlobal.width*0.5-loadingTextLayer.getWidth()*0.5;
    loadingTextLayer.y = LGlobal.height*0.5-loadingTextLayer.getHeight()*0.5;
    mask.addChild(loadingTextLayer);

    arcLayer.x = LGlobal.width*0.5;
    arcLayer.y = LGlobal.height*0.5;
    var r = 80;
    for(var i=0;i<360;i+=30){
        var child = new LSprite();
        child.graphics.drawArc(0,"#ffffff",[r,0,12,0,2*Math.PI],true,"#ffffff");
        child.rotate = i;
        child.alpha = 0.1+i/360;
        arcLayer.addChild(child);
    }
    var shadow = new LDropShadowFilter(0,0,"#FFFFFF",30);
    arcLayer.filters = [shadow];
    showLoadingGo=setInterval(function(){
        arcLayer.rotate += 30;
    },50)
}



//构建游戏场景
function addStage(){
    /*树杈1*/
    shotLayer=new LBitmap(new LBitmapData(datalist["dangong"]));
    shotLayer.x=(LGlobal.width - shotLayer.getWidth()/2)/2+50;
    shotLayer.y=LGlobal.height-shotLayer.getHeight()-50;
    gameLayer.addChild(shotLayer);

    /*石块*/
    var stone2=new LBitmap(new LBitmapData(datalist["stone2"]));
    stone2.x=(LGlobal.width - stone2.getWidth()/2)/2+2;
    stone2.y=LGlobal.height-stone2.getHeight()-35;
    gameLayer.addChild(stone2);

    /*2015*/
    var logo2015=new LBitmap(new LBitmapData(datalist["2015"]));
    logo2015.x=(LGlobal.width - logo2015.getWidth()/2)/2+80;
    logo2015.y=235;
    gameLayer.addChild(logo2015);

    /*撞击图层*/
    plainLayer = new LSprite();
    gameLayer.addChild(plainLayer);

    /*狐狸*/
    var fox=new LBitmap(new LBitmapData(datalist["fox"]));
    fox.x=38;
    fox.scaleX=0.8;
    fox.scaleY=0.8;
    fox.y=LGlobal.height-fox.getHeight()-30;
    gameLayer.addChild(fox);

    createStone_init();

    /*气泡*/
    qipaoLayer=new LSprite();
    var qipao=new LBitmap(new LBitmapData(datalist["qipao"]));
    qipaoLayer.addChild(qipao);
    qipao.scaleX=0.92;
    qipao.scaleY=0.92;
    qipaoLayer.x=-240   //10;
    qipaoLayer.y=LGlobal.height-qipao.getHeight()-180;
    gameLayer.addChild(qipaoLayer);

    /*提示文字*/
    qipaoTextLayer=new LSprite();
    qipaoTextNew=new LBitmap(new LBitmapData(datalist["tips1"]));
    qipaoTextNew.scaleX=0.96;
    qipaoTextNew.scaleY=0.96;
    qipaoTextNew.x=17;
    qipaoTextNew.y=36;
    qipaoTextLayer.addChild(qipaoTextNew)
    qipaoLayer.addChild(qipaoTextLayer);

    /*尾巴图层*/
    weibaLayer=new Weiba();
    weibaLayer.x=52;
    weibaLayer.y=LGlobal.height-weibaLayer.getHeight()-25;
    weibaLayer.scaleX=0.8;
    weibaLayer.scaleY=0.8;
    gameLayer.addChild(weibaLayer);
}

function createStone_init(){
    var bitmapData = new LBitmapData(datalist["player"]);
    player = new Player(LGlobal.width-100, LGlobal.height -75, bitmapData.width * 0.2, bitmapData.height * 0.1, bitmapData, 20);
    player.scaleX=0.8;
    player.scaleY=0.8;
    plainLayer.addChild(player);
}

/*石块*/
function createStone(){
    plainLayer.removeChild(player);
    var bitmapData = new LBitmapData(datalist["player"]);
    player = new Player(shotLayer.x+48,LGlobal.height-245, bitmapData.width * 0.2, bitmapData.height * 0.1, bitmapData, 20);
    player.scaleX=0.8;
    player.scaleY=0.8;
    bitmapData=null;
    plainLayer.addChild(player);
}

function getRandArr(arr){
    if(arr.length>0){
        var range=arr.length-1;
        var rand=Math.random();
        var index=Math.round(rand*range);
        return arr.splice(index,1);
    }else{
        return "none";
    }
}

function getReady(){
    gameLayer.addEventListener(LMouseEvent.MOUSE_DOWN,downStart);
    startX = player.x + player.getWidth()*0.5;
    startY = player.y + player.getHeight()*0.5;
}

function getRandArr(arr){
    if(arr.length>0){
        var range=arr.length-1;
        var rand=Math.random();
        var index=Math.round(rand*range);
        return arr.splice(index,1);
    }else{
        return "none";
    }
}

function showTipsText(){
    tipsListener=setInterval(function(){
        tipsIndex++;
        LTweenLite.to(qipaoTextNew,1,
            {
                alpha:0,
                onUpdate:function(){
                },
                onComplete:function(){
                    qipaoTextLayer.removeAllChild();
                },
                ease:Sine.easeIn
            }
        );

        qipaoTextNew=new LBitmap(new LBitmapData(datalist["tips"+tipsIndex]));
        qipaoTextNew.scaleX=0.96;
        qipaoTextNew.scaleY=0.96;
        qipaoTextNew.x=17;
        qipaoTextNew.y=36;
        qipaoTextNew.alpha=0;
        if(tipsIndex==5){
            tipsIndex=0;
        }

        LTweenLite.to(qipaoTextNew,1,
            {
                alpha:1,
                onUpdate:function(){
                },
                onComplete:function(){
                    qipaoTextLayer.addChild(qipaoTextNew);
                },
                ease:Sine.easeIn
            }
        );
    },4000);
}

function gameStart(){
    isStart=true;
    getReady();
    run();

    tipsRun(qipaoLayer,-240,qipaoLayer.y,10,qipaoLayer.y,0.4,5,0.1,function(){
        showTipsText();
    },0.2);

    var arr=[1,2,3,4];

    //彩蛋
    var ctrlList=[
        {"frames":10,"bullet":1,"move":[0,,0,0],img:"enemy"+getRandArr(arr),x:getRandomNum(20,56),y:getRandomNum(330,345),hp:1,isboss:false},
        {"frames":11,"bullet":1,"move":[0,0,0,0],img:"enemy"+getRandArr(arr),x:getRandomNum(LGlobal.width/2-180,LGlobal.width/2-60),y:getRandomNum(330,345),hp:1,isboss:false},
        {"frames":12,"bullet":1,"move":[0,0,0,0],img:"enemy"+getRandArr(arr),x:getRandomNum(LGlobal.width/2+40,LGlobal.width/2+80),y:getRandomNum(330,345),hp:1,isboss:false},
        {"frames":13,"bullet":1,"move":[0,0,0,0],img:"enemy"+getRandArr(arr),x:getRandomNum(LGlobal.width-120,LGlobal.width-80),y:getRandomNum(330,345),hp:1,isboss:false}
    ];

    eggs_num=ctrlList.length;

    gameLayer.addEventListener(LEvent.ENTER_FRAME, function(){
        for (var key in plainLayer.childList) {
            plainLayer.childList[key].onframe();
        }
        //狐狸位置
        if(player.x < 0 || player.x > LGlobal.width+player.getWidth() || player.y<200 || player.y > LGlobal.height+player.getHeight()){
            player.isdie = true;
            player.removeRun();
        }

        weibaLayer.run();
        setObject(ctrlList);
    });
}

function setObject(ctrlList){
    frame = 0;
    frames++;
    var ctrlObject = ctrlList[ctrlIndex];
    if(ctrlObject){
        ctrlIndex++;
        bitmapData = new LBitmapData(datalist[ctrlObject.img]);
        var enemy= new Enemy(ctrlObject.x,ctrlObject.y,0,bitmapData.height*0.5,bitmapData,ctrlObject["hp"]);
        var s=getRandomNum(60,76)/100;
        enemy.scaleX=s;
        enemy.scaleY=s;
        plainLayer.addChild(enemy);
    }else{
        return;
    }
}

/*tips*/
function tipsRun(overLayer,startX,startY,endX,endY,time,yspeed,dealy,fn,alpha){

    overLayer.x = startX;
    overLayer.y = startY;
    overLayer.alpha=alpha||1;
    overLayer.rotate = 0;
    overLayer.yspeed = -5;

    LTweenLite.to(overLayer,time,
        {
            x: endX || (LGlobal.width - overLayer.getWidth())*0.5,
            y: endY || (LGlobal.height - overLayer.getHeight())*0.5+30,
            yspeed:yspeed,
            delay:dealy,
            rotate:0,
            alpha:1,
            onUpdate:function(){
                overLayer.y += overLayer.yspeed;
            },
            onComplete:function(){
                if(fn){
                    fn();
                }
            },
            ease:Sine.easeIn
        }
    );
}

/*弹弓拉动效果开始*/

function downStart(event){

    /*不准射击*/
    if(!canShot){
        return;
    }

    if(event.offsetX > player.x && event.offsetX < player.x + player.getWidth() &&
        event.offsetY > player.y && event.offsetY < player.y + player.getHeight()){
        gameLayer.removeEventListener(LMouseEvent.MOUSE_DOWN,downStart);
        gameLayer.addEventListener(LMouseEvent.MOUSE_MOVE,downMove);
        gameLayer.addEventListener(LMouseEvent.MOUSE_UP,downOver);
    }
}

function downMove(event){
    var r = Math.sqrt(Math.pow((startX - event.selfX),2)+Math.pow((startY - event.selfY),2));
    if(r > 70){
        r = 70;
    }
    var angle = Math.atan2(event.selfY - startY,event.selfX - startX);
    player.x = Math.cos(angle) * r + startX - player.getWidth()*0.5;
    player.y = Math.sin(angle) * r + startY - player.getHeight()*0.5;

    if(event.offsetY>LGlobal.height-40){
        downOver();
    };

    zhiSound.play();
}

function downOver(){
    gameLayer.removeEventListener(LMouseEvent.MOUSE_UP,downOver);
    gameLayer.removeEventListener(LMouseEvent.MOUSE_MOVE,downMove);
    var startX2 = player.x + player.getWidth()*0.5;
    var startY2 = player.y + player.getHeight()*0.5;
    var r = Math.sqrt(Math.pow((startX - startX2),2)+Math.pow((startY - startY2),2));
    var angle = Math.atan2(startY2 - startY,startX2 - startX);
    player.addBodyCircle(player.getWidth()*0.5,player.getHeight()*0.5,player.getWidth()*0.5,1,0.5,0.4,0.5);
    var force=35;
    var vec = new LGlobal.box2d.b2Vec2(-force*r*Math.cos(angle),-force*r*Math.sin(angle));
    player.box2dBody.ApplyForce(vec, player.box2dBody.GetWorldCenter());
    zhiSound.close();
    dropSound.play();

    //彩蛋数量
    showStone=setTimeout(function(){
        dropSound.close();
        createStone();
        getReady();
    },300);
}


function run(){
    player.rotate = 0;
    player.x = LGlobal.width-100;
    player.y = LGlobal.height -75;
    player.yspeed = -5;
    LTweenLite.to(player,1,
        {
            x:shotLayer.x+48,
            y:LGlobal.height-245,
            yspeed:5,
            delay:0,
            rotate:-360,
            onUpdate:function(){
                player.y += player.yspeed;
            },
            onComplete:function(){
                getReady();
            },
            ease:Sine.easeIn
        }
    );
}

function sendLog(id){
    var logLink=$("#"+id);
    logLink.trigger("mousedown");
}

function eclipseTxt(txt){
    var _txt=txt.Trim();
    var res1=_txt.substr(0,12);
    if(_txt.length>12){
        var res2=_txt.substr(12,_txt.length);
        return [res1,res2+"..."];
    }else{
        return [res1,""];
    }
}


function gameFail(msg){

    function createDialog(newsTitle1,newsTitle2,newsHref){
        hideLoading(maskLayer);

        var overLayer = new LSprite();
        gameLayer.addChild(overLayer);

        /*提示图层*/
        var notice_bg=new LBitmap(new LBitmapData(datalist["notice"]));
        overLayer.addChild(notice_bg);

        notice_bg.x=(LGlobal.width - notice_bg.getWidth())/2;
        notice_bg.y=(LGlobal.height - notice_bg.getHeight()+30)/2+20;

        /*报纸*/
        var baozhi=new LBitmap(new LBitmapData(datalist["baozhi"]));
        baozhi.x=(LGlobal.width - baozhi.getWidth())/2;
        baozhi.y=(notice_bg.y - 70);
        overLayer.addChild(baozhi);

        /*关闭按钮*/
        var closeBtn=new LSprite();
        var clsoeBtn_bg=new LBitmap(new LBitmapData(datalist["closeBtn"]))
        clsoeBtn_bg.x=(notice_bg.x+notice_bg.getWidth()-100);
        clsoeBtn_bg.y=(notice_bg.y-clsoeBtn_bg.getHeight()*0.5+46);
        closeBtn.addChild(clsoeBtn_bg);
        overLayer.addChild(closeBtn);

        var params={
            startX:overLayer.x-8,
            startY:-(overLayer.getHeight()+10),
            endX: overLayer.x-8,
            endY:(LGlobal.height - notice_bg.getHeight()+30)/2-160,
            time:0.4,
            yspeed:10,
            dealy:0.1
        };

        tipsRun(overLayer,params.startX,params.startY,params.endX,params.endY,params.time,params.yspeed,params.dealy,function(){
            tipsRun(overLayer,overLayer.x,overLayer.y,overLayer.x,overLayer.y-30,0.1,5,0.1,function(){
                console.log("ready");
            });
        });

        var closeMask=function(){
            sendLog("closeBtn");
            canShot=true;
            startSound.play();
            tipsRun(overLayer,overLayer.x,overLayer.y,overLayer.x,overLayer.y+30,0,10,0.1,function(){
                tipsRun(overLayer,overLayer.x,overLayer.y,overLayer.x,-(overLayer.getHeight()+10),0.1,6,0.1,function(){
                    overLayer.die();
                    destoryMask();
                    gameLayer.removeChild(overLayer);
                });
            });
        };

        var rePlay=function(){
            sendLog("replayBtn");
            startSound.play();
            isStart=false;
            canShot=true;
            tipsRun(overLayer,overLayer.x,overLayer.y,overLayer.x,overLayer.y+30,0,10,0.1,function(){
                tipsRun(overLayer,overLayer.x,overLayer.y,overLayer.x,-(overLayer.getHeight()+10),0.1,6,0.1,function(){
                    destoryMask();
                    qipaoTextLayer.removeAllChild();
                    tipsRun(qipaoLayer,10,qipaoLayer.y,-240,qipaoLayer.y,0.2,5,0.1,function(){
                        gameLayer.die();
                        gameLayer.graphics.drawRect(1,"#a8ef68",[0,0,LGlobal.width,LGlobal.height],true,"#a8ef68");
                        clearTimeout(showStone);
                        clearInterval(tipsListener);
                        gameLayer.removeAllChild();
                        gameLayer.addChild(bgbitmap);
                        addStage();
                        restoreGlobal();
                        gameStart();
                    },0.2);
                });
            });
        };

        closeBtn.addEventListener(LMouseEvent.MOUSE_DOWN,function(){

            if(msg=="go"){
                closeMask();
            }else{
                rePlay();
            }
        });

        /*提示文字*/
        var failTxt=new LBitmap(new LBitmapData(datalist["fail"]));
        failTxt.x=(notice_bg.x+failTxt.getWidth()*0.25)+30;
        failTxt.y=(notice_bg.y+failTxt.getHeight()*0.25)+58;
        failTxt.scaleX=0.9;
        failTxt.scaleY=0.9;
        overLayer.addChild(failTxt);

        /*看新闻内容一*/
        var newsBox=new LSprite();
        var newsBg=new LBitmap(new LBitmapData(datalist["newsArea"]));
        newsBg.x=(notice_bg.x+newsBg.getWidth()*0.25)+10;
        newsBg.y=(notice_bg.y+newsBg.getHeight()*0.25)+128;
        newsBg.scaleX= 0.85;
        newsBg.scaleY= 0.85;

        var newsTitleTxt_1=new LTextField();
        newsTitleTxt_1.text=newsTitle1;
        newsTitleTxt_1.size=20;
        newsTitleTxt_1.x= newsBg.x+10;
        newsTitleTxt_1.y=newsBg.y+22;
        newsTitleTxt_1.weight="bolder";
        newsTitleTxt_1.color="#fa5353";

        newsBox.addChild(newsBg);
        newsBox.addChild(newsTitleTxt_1);

        /*看新闻内容二*/
        var newsTitleTxt_2=new LTextField();
        newsTitleTxt_2.text=newsTitle2;
        newsTitleTxt_2.size=20;
        newsTitleTxt_2.x= newsBg.x+10;
        newsTitleTxt_2.y=newsBg.y+52;
        newsTitleTxt_2.weight="bolder";
        newsTitleTxt_2.color="#fa5353";
        newsBox.addChild(newsTitleTxt_2);
        overLayer.addChild(newsBox);

        newsBox.addEventListener(LMouseEvent.MOUSE_DOWN,function(e){
            location.href=newsHref;
            return false;
        });

        /*分享给好友提示*/
        var shareLogoLayer=new LSprite();
        var sharelogo = new LBitmap(new LBitmapData(datalist["sharelogo"]));
        sharelogo.x = (LGlobal.width-sharelogo.getWidth()-35);
        sharelogo.y =20;
        shareLogoLayer.addChild(sharelogo);
        shareLogoLayer.addEventListener(LMouseEvent.MOUSE_DOWN,function(){
            if(hitNum==eggs_num){
                rePlay();
            }else{
                closeMask();
            }
        });

        /*继续进攻*/
        var buttonBitmap2 = new LBitmap(new LBitmapData(datalist["clickBtn"]));
        var retryBtn= new LSprite();
        buttonBitmap2.x = (newsBg.x+65);
        buttonBitmap2.y = (newsBg.y+95+16+6);
        retryBtn.addChild(buttonBitmap2);
        var txt2=new LTextField();
        txt2.text=msg=="go"?"继续进攻~":"再玩一次~";
        txt2.size=22;
        txt2.x=buttonBitmap2.x+34;
        txt2.y=buttonBitmap2.y+14;
        txt2.weight="bolder";
        txt2.color="#ffffff";
        retryBtn.addChild(txt2);
        overLayer.addChild(retryBtn);
        retryBtn.addEventListener(LMouseEvent.MOUSE_DOWN,function(){
            sendLog("closeBtn");
            if(msg=="go"){
                closeMask();
            }else{
                rePlay();
            }
        });

        /*分享给好友*/
        var buttonBitmap3 = new LBitmap(new LBitmapData(datalist["clickBtn"]));
        var shareBtn= new LSprite();
        buttonBitmap3.x = (newsBg.x+65);
        buttonBitmap3.y = (newsBg.y+95+90+6);//32为按钮高度
        shareBtn.addChild(buttonBitmap3);
        var txt3=new LTextField();
        txt3.text="分享给好友";
        txt3.size=22;
        txt3.x=buttonBitmap3.x+28;
        txt3.y=buttonBitmap3.y+14;
        txt3.weight="bolder";
        txt3.color="#ffffff";
        shareBtn.addChild(txt3);
        overLayer.addChild(shareBtn);
        shareBtn.addEventListener(LMouseEvent.MOUSE_DOWN,function(){
            sendLog("shareBtn");
            if(LGlobal.platforms=="sohuNews"){
                ShareTools.shareThisPage();
            }else{
                overLayer.removeAllChild();
                overLayer.addChild(shareLogoLayer);

            }
        });

        /*sohuIcon*/
        if(!(LGlobal.platforms=="sohuNews")){
            var sohuIcon = new LBitmap(new LBitmapData(datalist["sohu"]));
            var sohuBtn= new LSprite();
            sohuIcon.x = (notice_bg.x+123);
            sohuIcon.y = (txt3.y+65);      //32为按钮高度
            sohuBtn.addChild(sohuIcon);

            var link1=new LTextField();
            link1.text="打开搜狐新闻才能玩天天";
            link1.size=18;
            link1.x=sohuIcon.x+76;
            link1.y=sohuIcon.y+4;
            link1.weight="bolder";
            link1.color="#ec8618";

            var link2=new LTextField();
            link2.text="中红包哦！前往下载>>";
            link2.size=18;
            link2.x=sohuIcon.x+76;
            link2.y=sohuIcon.y+36;
            link2.weight="bolder";
            link2.color="#ec8618";

            sohuBtn.addChild(link1);
            sohuBtn.addChild(link2);
            overLayer.addChild(sohuBtn);
            sohuBtn.addEventListener(LMouseEvent.MOUSE_DOWN,function(){
                location.href="http://s.itc.cn/adown1024";

            });
        }else{
            var sohuIcon1 = new LBitmap(new LBitmapData(datalist["sohu"]));
            var sohuBtn1= new LSprite();
            sohuIcon1.x = buttonBitmap3.x+62;
            sohuIcon1.y = buttonBitmap3.y+78;
            sohuBtn1.addChild(sohuIcon1);
            overLayer.addChild(sohuBtn1);
        }
    };

    if(!localStorage.getItem("newsData")){
        $.ajax({
            url: 'http://api.k.sohu.com/api/channel/news.go?rt=jsoncallback&callback=fcallback&needCache=0&channelId=1&page=1&num=50',
            beforeSend: function () {
                console.log("beforeSend");
            },
            dataType: "jsonp",
            jsonp: "fcallback",
            timeout: 5000,
            success: function (data) {
                if(data && data.articles.length>0){
                    var newsTitleFirst=eclipseTxt(data.articles[newsIndex].title);
                    var platform=LGlobal.android ? "":"iphone";
                    var linkId=LGlobal.platforms=="sohuNews" ?
                    "sohunews"+platform+"://pr/"+data.articles[newsIndex].link2:
                    "http://m.k.sohu.com/t/n"+data.articles[newsIndex].newsId+"/1";
                    createDialog(newsTitleFirst[0],newsTitleFirst[1],linkId);
                    localStorage.setItem("newsData",JSON.stringify(data.articles));
                    newsIndex++;
                }
            },
            error: function () {
                //清空loading
                canShot=true;
                gameLayer.removeChild(maskLayer);
                clearInterval(showLoadingGo);
                if(hitNum==eggs_num){
                    gameFail("stop");
                }else{
                    gameFail("go");
                }
            }
        });
    }else{
        var newsCont=JSON.parse(localStorage.getItem("newsData"));
        if(newsIndex< newsCont.length){
            var newsTitle=eclipseTxt(newsCont[newsIndex].title);
            var platform=LGlobal.android ? "":"iphone";
            var linkId2 = LGlobal.platforms == "sohuNews" ?
            "sohunews"+platform+"://pr/"+newsCont[newsIndex].link2 :
            "http://m.k.sohu.com/t/n"+newsCont[newsIndex].newsId+"/1";
            createDialog(newsTitle[0],newsTitle[1],linkId2);
            newsIndex++;
        }else{
            newsIndex=newsCont.length-1;
            var newsTitle=eclipseTxt(newsCont[newsIndex].title);
            var platform3=LGlobal.android ?"":"iphone";
            var linkId3 = LGlobal.platforms == "sohuNews" ?
            "sohunews"+platform3+"://pr/"+newsCont[newsIndex].link2 :
            "http://m.k.sohu.com/t/n"+newsCont[newsIndex].newsId+"/1";
            createDialog(newsTitle[0],newsTitle[1],linkId3);
            newsIndex=0;
        }
    }
}

function gameSuccess(url){
    hideLoading(maskLayer);

    var overLayer = new LSprite();
    gameLayer.addChild(overLayer);

    /*提示图层*/
    var notice_bg=new LBitmap(new LBitmapData(datalist["notice"]));
    overLayer.addChild(notice_bg);

    notice_bg.x=(LGlobal.width - notice_bg.getWidth())/2;
    notice_bg.y=(LGlobal.height - notice_bg.getHeight()+30)/2+20;

    /*红包*/
    var hongbao=new LBitmap(new LBitmapData(datalist["hongbao"]));
    hongbao.x=(LGlobal.width - hongbao.getWidth())/2;
    hongbao.y=(notice_bg.y - 70);
    overLayer.addChild(hongbao);

    /*关闭按钮*/
    var closeBtn=new LSprite();
    var clsoeBtn_bg=new LBitmap(new LBitmapData(datalist["closeBtn"]))
    clsoeBtn_bg.x=(notice_bg.x+notice_bg.getWidth()-100);
    clsoeBtn_bg.y=(notice_bg.y-clsoeBtn_bg.getHeight()*0.5+46);
    closeBtn.addChild(clsoeBtn_bg);
    overLayer.addChild(closeBtn);

    var params={
        startX:overLayer.x-8,
        startY:-(overLayer.getHeight()+10),
        endX: overLayer.x-8,
        endY:(LGlobal.height - notice_bg.getHeight()+30)/2-160,
        time:0.4,
        yspeed:10,
        dealy:0.1
    };

    tipsRun(overLayer,params.startX,params.startY,params.endX,params.endY,params.time,params.yspeed,params.dealy,function(){
        tipsRun(overLayer,overLayer.x,overLayer.y,overLayer.x,overLayer.y-30,0.1,6,0.1,function(){});
    });

    var closeMask=function(){
        sendLog("closeBtn");
        canShot=true;
        startSound.play();
        tipsRun(overLayer,overLayer.x,overLayer.y,overLayer.x,overLayer.y+30,0,10,0.1,function(){
            tipsRun(overLayer,overLayer.x,overLayer.y,overLayer.x,-(overLayer.getHeight()+10),0.1,6,0.1,function(){
                overLayer.die();
                destoryMask();
                gameLayer.removeChild(overLayer);
            });
        });
    };

    var rePlay=function(){
        sendLog("replayBtn");
        startSound.play();
        isStart=false;
        canShot=true;
        tipsRun(overLayer,overLayer.x,overLayer.y,overLayer.x,overLayer.y+30,0,10,0.1,function(){
            tipsRun(overLayer,overLayer.x,overLayer.y,overLayer.x,-(overLayer.getHeight()+10),0.1,6,0.1,function(){
                destoryMask();
                qipaoTextLayer.removeAllChild();
                tipsRun(qipaoLayer,10,qipaoLayer.y,-240,qipaoLayer.y,0.2,5,0.1,function(){
                    gameLayer.die();
                    gameLayer.graphics.drawRect(1,"#a8ef68",[0,0,LGlobal.width,LGlobal.height],true,"#a8ef68");
                    clearTimeout(showStone);
                    clearInterval(tipsListener);
                    gameLayer.removeAllChild();
                    gameLayer.addChild(bgbitmap);
                    addStage();
                    restoreGlobal();
                    gameStart();
                },0.2);
            });
        });
    };

    closeBtn.addEventListener(LMouseEvent.MOUSE_DOWN,rePlay);

    /*提示文字*/
    var successTxt=new LBitmap(new LBitmapData(datalist["success"]))
    successTxt.x=(notice_bg.x+successTxt.getWidth()*0.25)+30;
    successTxt.y=(notice_bg.y+successTxt.getHeight()*0.25)+52;
    successTxt.scaleX=0.9;
    successTxt.scaleY=0.9;
    overLayer.addChild(successTxt);

    /*领奖按钮*/
    var buttonBitmap = new LBitmap(new LBitmapData(datalist["clickBtn"]));

    var getLotteryBtn= new LSprite();
    getLotteryBtn.addChild(buttonBitmap);
    buttonBitmap.x = (successTxt.x+75);
    buttonBitmap.y = (successTxt.y+125);
    var txt1=new LTextField();
    txt1.text="立刻领奖~";
    txt1.size=22;
    txt1.x=buttonBitmap.x+24;
    txt1.y=buttonBitmap.y+14;
    txt1.weight="bolder";
    txt1.color="#ffffff";
    getLotteryBtn.addChild(txt1);
    overLayer.addChild(getLotteryBtn);
    getLotteryBtn.addEventListener(LMouseEvent.MOUSE_DOWN,function(){
        sendLog("getLotteryBtn");
        location.href=url;
    });

    /*再玩一次*/
    var buttonBitmap2 = new LBitmap(new LBitmapData(datalist["clickBtn"]));
    var retryBtn= new LSprite();
    buttonBitmap2.x = (successTxt.x+75);
    buttonBitmap2.y = (successTxt.y+125+72);      //32为按钮高度
    retryBtn.addChild(buttonBitmap2);
    var txt2=new LTextField();
    txt2.text="再玩一次~";
    txt2.size=22;
    txt2.x=buttonBitmap2.x+24;
    txt2.y=buttonBitmap2.y+14;
    txt2.weight="bolder";
    txt2.color="#ffffff";
    retryBtn.addChild(txt2);
    overLayer.addChild(retryBtn);
    retryBtn.addEventListener(LMouseEvent.MOUSE_DOWN,rePlay);

    /*分享给好友*/
    var buttonBitmap3 = new LBitmap(new LBitmapData(datalist["clickBtn"]));
    var shareBtn= new LSprite();
    buttonBitmap3.x = (successTxt.x+75);
    buttonBitmap3.y = (successTxt.y+125+144);      //32为按钮高度
    shareBtn.addChild(buttonBitmap3);
    var txt3=new LTextField();
    txt3.text="分享给好友";
    txt3.size=22
    txt3.x=buttonBitmap3.x+24;
    txt3.y=buttonBitmap3.y+14;
    txt3.weight="bolder";
    txt3.color="#ffffff";
    shareBtn.addChild(txt3);
    overLayer.addChild(shareBtn);
    shareBtn.addEventListener(LMouseEvent.MOUSE_DOWN,function(){
        sendLog("shareBtn");
        if(LGlobal.platforms=="sohuNews"){
            ShareTools.shareThisPage();
        }else{
            overLayer.removeAllChild();
            overLayer.addChild(shareLogoLayer);
        }
    });

    /*分享给好友提示*/
    var shareLogoLayer=new LSprite();
    var sharelogo = new LBitmap(new LBitmapData(datalist["sharelogo"]));
    sharelogo.x = (LGlobal.width-190);
    sharelogo.y = 30;
    shareLogoLayer.addChild(sharelogo);
    shareLogoLayer.addEventListener(LMouseEvent.MOUSE_DOWN,function(){
        if(hitNum==eggs_num){
            rePlay();
        }else{
            closeMask();
        }
    });

    /*sohuIcon*/
    if(!(LGlobal.platforms=="sohuNews")){
        var sohuIcon = new LBitmap(new LBitmapData(datalist["sohu"]));
        var sohuBtn= new LSprite();
        sohuIcon.x = (notice_bg.x+123);
        sohuIcon.y = (txt3.y+65);      //32为按钮高度
        sohuBtn.addChild(sohuIcon);

        var link1=new LTextField();
        link1.text="打开搜狐新闻才能玩天天";
        link1.size=18;
        link1.x=sohuIcon.x+76;
        link1.y=sohuIcon.y+4;
        link1.weight="bolder";
        link1.color="#ec8618";

        var link2=new LTextField();
        link2.text="中红包哦！前往下载>>";
        link2.size=18;
        link2.x=sohuIcon.x+76;
        link2.y=sohuIcon.y+36;
        link2.weight="bolder";
        link2.color="#ec8618";

        sohuBtn.addChild(link1);
        sohuBtn.addChild(link2);
        overLayer.addChild(sohuBtn);
        sohuBtn.addEventListener(LMouseEvent.MOUSE_DOWN,function(){
            sendLog("h5_71_4");
            location.href="http://s.itc.cn/adown1024";
        });
    }else{
        var sohuIcon1 = new LBitmap(new LBitmapData(datalist["sohu"]));
        var sohuBtn1= new LSprite();
        sohuIcon1.x = buttonBitmap3.x+62;
        sohuIcon1.y = buttonBitmap3.y+78;      //32为按钮高度
        sohuBtn1.addChild(sohuIcon1);
        overLayer.addChild(sohuBtn1);
    }
}

function restoreGlobal(){
    hitNum=0;
    ctrlIndex=0;
}

